#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Author  : lkm
# 案例：P1 例1.1 机床厂总利润最大化

"""
scipy.optimize.linprog(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None, bounds=None,
                       method='simplex', callback=None, options=None)
"""

from scipy.optimize import linprog
import numpy as np

def linear_programming_machie(f, Aub, Bub, Aeq, Beq, ub1, ub2):
    c = np.array(f) # f价值向量
    A_ub = np.array(Aub) # A矩阵
    B_ub = np.array(Bub) # b资源向量
    A_eq = np.array(Aeq) # Aeq矩阵
    B_eq = np.array(Beq) # beq列向量
    x1 = ub1 #
    x2 = ub2 #
    # 最大值加负号，最小值不加负号
    result = linprog(-c,A_ub,B_ub,A_eq,B_eq,bounds=(x1,x2))
    print(result)
    return result

if __name__ == '__main__':
    f = [4, 3]
    Aub = [[2, 1],[1, 1]]
    Bub = [10, 8]
    Aeq = [[0, 1]]
    Beq = [7]
    ub1 = (0, None)
    ub2 = (0, None)
    linear_programming_machie(f, Aub, Bub, Aeq, Beq, ub1, ub2)